package jdbc1;

import java.sql.*;

/**
 * @author oldliu
 * @since 1.0
 */
public class Meta {
    static {
        try {
            //static{}执行了
            Class.forName("com.mysql.cj.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();

        }
    }

    public static void main(String[] args) {
        String url = "jdbc:mysql://localhost:3308/java83?useUnicode=true&characterEncoding=utf8&useSSL=false" +
                "&serverTimezone=Asia/Shanghai";
        Connection con=null;
        PreparedStatement ps=null;
        String sql="select * from s_student";
        try {
            con = DriverManager.getConnection(url, "xukang", "Xu1234");
            DatabaseMetaData metaData = con.getMetaData();
            System.out.println(metaData.getDatabaseProductName());
            System.out.println(metaData.getDatabaseProductVersion());

            ps = con.prepareStatement(sql);
            ResultSet rs = ps.executeQuery();
            ResultSetMetaData md = rs.getMetaData();
            for (int i = 1; i <=md.getColumnCount() ; i++) {
                System.out.println("第"+i+"列:"+md.getColumnLabel(i)+"=>"+md.getColumnTypeName(i)+","+md.getColumnClassName(i));
            }
            rs.close();
            ps.close();
            con.close();
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
        }
    }
}
